//
//  MCImagePreViewController.swift
//  Mercury
//
//  Created by 范强伟 on 2023/5/17.
//  Copyright © 2023 Mercury. All rights reserved.
//

import UIKit

class MCImagePreViewController: UIViewController {

    /// 图片数组地址
    let urls : [String]
    let index: Int
    
    class func showPreImageView(viewController: UIViewController,urls: [String],index: Int){
        let vc = MCImagePreViewController(urls: urls, index: index)
        vc.modalPresentationStyle = .overFullScreen
        viewController.present(vc, animated: false)
    }
    
    
    
    init(urls: [String],index: Int) {
        self.urls = urls
        self.index = index
        super.init(nibName: nil, bundle: nil)
        imageViewList.selectIndex = selectIndex
        imageViewList.collectionList = urls
        
    }
     
    var selectIndex: Int = 0 {
        didSet{
            imageViewList.selectIndex = selectIndex
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
      
        view.backgroundColor = .black
        view.addSubview(imageViewList)
//        view.insertSubview(imageViewList, belowSubview: naviView)
        imageViewList.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
        view.addSubview(closeBtn)
        closeBtn.frame = CGRect(x: 10, y: safeAreaEdgeInsets.top + 7, width: 30, height: 30)
    }
    
    lazy var imageViewList: MCAppImagePreView = {
        let imageView = MCAppImagePreView()
        return imageView
    }()
    
    lazy var closeBtn: UIButton = {
        let view = UIButton()
        view.setImage(UIImage(named: "map_ic_back"), for: .normal)
        view.addTarget(self, action: #selector(closeClickAction), for: .touchUpInside)
         
        return view
    }()
    
    @objc func closeClickAction(){
        self.dismiss(animated: false)
    }

}
